package com.play.ballen.mall.ui

import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import com.play.ballen.R
import com.play.ballen.databinding.ActivityMallRecordBinding
import com.yuven.appframework.adapter.BaseViewPagerAdapter
import com.yuven.appframework.base.BaseStdTitleActivity
import com.yuven.baselib.component.viewmodel.BaseViewModel.EmptyVM
import com.yuven.baselib.utils.ResourceUtil

class MallRecordActivity : BaseStdTitleActivity<EmptyVM, ActivityMallRecordBinding>() {

    private val fragmentList by lazy {
        arrayListOf<Fragment>(
            MallRecordFragment.newInstance(TYPE_RECORD_BUY),
            MallRecordFragment.newInstance(TYPE_RECORD_SALE)
        )
    }

    private lateinit var adapter: BaseViewPagerAdapter
    private val titles = arrayListOf(
        ResourceUtil.getString(R.string.mall_record_order_buy),
        ResourceUtil.getString(R.string.mall_record_order_sale)
    )

    companion object {

        const val TYPE_RECORD_BUY = "0"
        const val TYPE_RECORD_SALE = "1"

        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, MallRecordActivity::class.java)
            context.startActivity(starter)
        }
    }

    override fun viewModelClass(): Class<EmptyVM> {
        return EmptyVM::class.java
    }

    override fun contentLayoutId(): Int {
        return R.layout.activity_mall_record
    }

    override fun initData() {
        adapter = BaseViewPagerAdapter(supportFragmentManager, fragmentList, titles)
        dataBinding.viewPager.adapter = adapter
        dataBinding.viewPager.offscreenPageLimit = fragmentList.size
        dataBinding.tabLayout.setViewPager(dataBinding.viewPager)
    }

    override fun initIntent(intent: Intent?) {
    }

    override fun getToolBarTitle(): String = ResourceUtil.getString(R.string.mall_record_title)
}